package info.scholtus.open.provider;

import info.scholtus.open.util.ParserUtils;
import android.net.Uri;
import android.provider.BaseColumns;

public class Contract {
    
    public static final String CONTENT_AUTHORITY = "info.scholtus.android.apps.open";

    public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);

	public static final String PATH_CATEGORIES = "categories";
	public static final String PATH_VENDORS = "vendors";
	public static final String PATH_SITES = "sites";
	public static final String PATH_PROPERTIES = "properties";
	public static final String PATH_BLOCKS = "blocks";
	
	interface CategoriesColumns {
		String CATEGORY_ID = "category_id";
		String CATEGORY_NAME = "category_name";
		String CATEGORY_ABSTRACT = "category_abstract";
	}
	
	interface VendorsColumns {
		String VENDOR_ID = "vendor_id";
		String VENDOR_NAME = "vendor_name";
	}
	
	interface SitesColumns {
		String SITE_ID = "site_id";
		String SITE_NAME = "site_name";
		String SITE_ABSTRACT = "site_abstract";
	}
	
	interface PropertiesColumns {
		String PROPERTY_ID = "property_id";
		String PROPERTY_TYPE = "property_type";
		String PROPERTY_VALUE = "property_value";
	}
	
	interface BlocksColumns {
		String BLOCK_ID = "block_id";
		String BLOCK_SPAN = "block_span";
		String BLOCK_DATE_START = "block_date_start";
		String BLOCK_DATE_END = "block_date_end";
		String BLOCK_HOUR_START = "block_hour_start";
		String BLOCK_HOUR_END = "block_hour_end";
	}
	
	public static class Categories implements CategoriesColumns, BaseColumns {

        public static final Uri CONTENT_URI =
                BASE_CONTENT_URI.buildUpon().appendPath(PATH_CATEGORIES).build();

        public static final String CONTENT_TYPE =
                "vnd.android.cursor.dir/vnd.scholtus.category";
        public static final String CONTENT_ITEM_TYPE =
                "vnd.android.cursor.item/vnd.scholtus.category";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = CategoriesColumns.CATEGORY_NAME + " ASC";

        /** Build {@link Uri} for requested {@link #CATEGORY_ID}. */
        public static Uri buildCategoryUri(String categoryId) {
            return CONTENT_URI.buildUpon().appendPath(categoryId).build();
        }

        /**
         * Build {@link Uri} that references any {@link Vendors} associated with
         * the requested {@link #CATEGORY_ID}.
         */
        public static Uri buildVendorsUri(String categoryId) {
            return CONTENT_URI.buildUpon().appendPath(categoryId).appendPath(PATH_VENDORS).build();
        }

        /** Read {@link #CATEGORY_ID} from {@link Categories} {@link Uri}. */
        public static String getCategoryId(Uri uri) {
            return uri.getPathSegments().get(1);
        }

        /**
         * Generate a {@link #CATEGORY_ID} that will always match the requested
         * {@link Categories} details.
         */
        public static String generateCategoryId(String name) {
            return ParserUtils.sanitizeId(name);
        }
	}
	

	public static class Vendors implements VendorsColumns, BaseColumns {

        public static final Uri CONTENT_URI =
                BASE_CONTENT_URI.buildUpon().appendPath(PATH_VENDORS).build();

        public static final String CONTENT_TYPE =
                "vnd.android.cursor.dir/vnd.scholtus.vendor";
        public static final String CONTENT_ITEM_TYPE =
                "vnd.android.cursor.item/vnd.scholtus.vendor";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = VendorsColumns.VENDOR_NAME + " ASC";

        /** Build {@link Uri} for requested {@link #VENDOR_ID}. */
        public static Uri buildVendorUri(String vendorId) {
            return CONTENT_URI.buildUpon().appendPath(vendorId).build();
        }

        /**
         * Build {@link Uri} that references any {@link Sites} associated with
         * the requested {@link #VENDOR_ID}.
         */
        public static Uri buildSitesUri(String vendorId) {
            return CONTENT_URI.buildUpon().appendPath(vendorId).appendPath(PATH_SITES).build();
        }

        /** Read {@link #VENDOR_ID} from {@link Vendors} {@link Uri}. */
        public static String getVendorId(Uri uri) {
            return uri.getPathSegments().get(1);
        }

        /**
         * Generate a {@link #VENDOR_ID} that will always match the requested
         * {@link Vendors} details.
         */
        public static String generateVendorId(String name) {
            return ParserUtils.sanitizeId(name);
        }
		
	}
	

	public static class Sites implements SitesColumns, BaseColumns {

        public static final Uri CONTENT_URI =
                BASE_CONTENT_URI.buildUpon().appendPath(PATH_SITES).build();

        public static final String CONTENT_TYPE =
                "vnd.android.cursor.dir/vnd.scholtus.site";
        public static final String CONTENT_ITEM_TYPE =
                "vnd.android.cursor.item/vnd.scholtus.site";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = SitesColumns.SITE_NAME + " ASC";

        /** Build {@link Uri} for requested {@link #SITE_ID}. */
        public static Uri buildSiteUri(String siteId) {
            return CONTENT_URI.buildUpon().appendPath(siteId).build();
        }

        /**
         * Build {@link Uri} that references any {@link Blocks} associated with
         * the requested {@link #SITE_ID}.
         */
        public static Uri buildBlocksUri(String siteId) {
            return CONTENT_URI.buildUpon().appendPath(siteId).appendPath(PATH_BLOCKS).build();
        }

        /**
         * Build {@link Uri} that references any {@link Properties} associated with
         * the requested {@link #SITE_ID}.
         */
        public static Uri buildPropertiesUri(String siteId) {
            return CONTENT_URI.buildUpon().appendPath(siteId).appendPath(PATH_PROPERTIES).build();
        }

        /** Read {@link #SITE_ID} from {@link Sites} {@link Uri}. */
        public static String getSiteId(Uri uri) {
            return uri.getPathSegments().get(1);
        }

        /**
         * Generate a {@link #SITE_ID} that will always match the requested
         * {@link Sites} details.
         */
        public static String generateSiteId(String name) {
            return ParserUtils.sanitizeId(name);
        }
	}
	

	public static class Properties implements PropertiesColumns, BaseColumns {

        public static final Uri CONTENT_URI =
                BASE_CONTENT_URI.buildUpon().appendPath(PATH_PROPERTIES).build();

        public static final String CONTENT_TYPE =
                "vnd.android.cursor.dir/vnd.scholtus.property";
        public static final String CONTENT_ITEM_TYPE =
                "vnd.android.cursor.item/vnd.scholtus.property";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = PropertiesColumns.PROPERTY_TYPE + " ASC,"
        		+ PropertiesColumns.PROPERTY_VALUE + "ASC";

        /** Build {@link Uri} for requested {@link #PROPERTY_ID}. */
        public static Uri buildPropertyUri(String propertyId) {
            return CONTENT_URI.buildUpon().appendPath(propertyId).build();
        }

        /** Read {@link #PROPERTY_ID} from {@link Properties} {@link Uri}. */
        public static String getPropertyId(Uri uri) {
            return uri.getPathSegments().get(1);
        }

        /**
         * Generate a {@link #PROPERTY_ID} that will always match the requested
         * {@link Properties} details.
         */
        public static String generatePropertyId(String name) {
            return ParserUtils.sanitizeId(name);
        }
	}
	
	public static class Blocks implements BlocksColumns, BaseColumns {

        public static final Uri CONTENT_URI =
                BASE_CONTENT_URI.buildUpon().appendPath(PATH_BLOCKS).build();

        public static final String CONTENT_TYPE =
                "vnd.android.cursor.dir/vnd.scholtus.block";
        public static final String CONTENT_ITEM_TYPE =
                "vnd.android.cursor.item/vnd.scholtus.block";

        /** Default "ORDER BY" clause. */
        public static final String DEFAULT_SORT = BlocksColumns.BLOCK_SPAN + " ASC,"
        		+ BlocksColumns.BLOCK_DATE_START + "ASC"
        		+ BlocksColumns.BLOCK_HOUR_START + "ASC"
        		+ BlocksColumns.BLOCK_DATE_END + "ASC"
        		+ BlocksColumns.BLOCK_HOUR_END + "ASC";

        /** Build {@link Uri} for requested {@link #BLOCK_ID}. */
        public static Uri buildBlockUri(String blockId) {
            return CONTENT_URI.buildUpon().appendPath(blockId).build();
        }

        /** Read {@link #BLOCK_ID} from {@link Blocks} {@link Uri}. */
        public static String getBlockId(Uri uri) {
            return uri.getPathSegments().get(1);
        }

        /**
         * Generate a {@link #BLOCK_ID} that will always match the requested
         * {@link Blocks} details.
         */
        public static String generateBlockId(String name) {
            return ParserUtils.sanitizeId(name);
        }
	}
	
    private Contract() {
    }
}
